package servlet;

import dao.MajorDao;
import pojo.Major;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.*;

@WebServlet(value = "/addMajorServlet")
public class AddMajorServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1. 收集数据
        request.setCharacterEncoding("utf-8");
        String id=request.getParameter("id");
        String majorName=request.getParameter("majorName");
        Major major = new Major();
        major.setMajorName(majorName);
        major.setId(id);
        MajorDao.addMajor(major);
        //3. 选择视图显示结果
        response.sendRedirect("/lab08/showAllMajorsServlet");
    }
}
